﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class BANDAO:IData<BAN> 
 	{
		public BANDAO(String myconnecString) : base(myconnecString) { }

		protected override int InsertOnSubmit(ref BAN item, int t) {
			 SqlParameter p = new SqlParameter(); 
			 if( t == 0)
				p.Direction = ParameterDirection.Output;
			 p.ParameterName = "@" + BAN.c_ID;
			 p.Value = item.ID;
			 Object obj = item.ID; 
			int i = connec.ExecuteNonQuery("sp_BAN", CommandType.StoredProcedure,p,ref obj,new SqlParameter("@flag", t),
				 new SqlParameter("@" + BAN.c_TENBAN, item.TENBAN), new SqlParameter("@" + BAN.c_MOTABAN, item.MOTABAN),
				 new SqlParameter("@" + BAN.c_VUID, item.VUID));
			if(t == 0)
				item.ID = Convert.ToInt64(obj);
			return i;
		}

		public override BAN GetItem(IDataReader dr)
		{
			BAN obj = new BAN();
			obj.ID = Convert.ToInt64(dr[BAN.c_ID]);
			obj.TENBAN = Convert.ToString(dr[BAN.c_TENBAN]);
			obj.MOTABAN = Convert.ToString(dr[BAN.c_MOTABAN]);
			obj.VUID = Convert.ToInt64(dr[BAN.c_VUID]);
			return obj;
		}

		public override List<BAN> GetAll()
		{
			return GetAll("sp_GetAllBAN", CommandType.StoredProcedure);
		}

		public override BAN GetItemById(object id)
		{
			return GetAll().SingleOrDefault(p => p.ID == Convert.ToInt64(id));
		}
		public override BAN GetItemById(BAN item){
			throw new NotImplementedException();
		}

	}

 }
